package org.linlinjava.litemall.db.service;

import org.linlinjava.litemall.db.dao.AgedmallOnlineServiceMapper;
import org.linlinjava.litemall.db.dao.AgedmallServiceOrderMapper;
import org.linlinjava.litemall.db.domain.AgedmallOnlineService;
import org.linlinjava.litemall.db.domain.AgedmallServiceOrder;
import org.linlinjava.litemall.db.domain.AgedmallServiceOrderExample;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author huangfei
 * @create 2021-11-16 15:45
 */
@Service
public class AgedmallOnlinesService {

    @Resource
    private AgedmallOnlineServiceMapper agedmallOnlineServiceMapper;
    @Resource
    private AgedmallServiceOrderMapper agedmallServiceOrderMapper;

    /**
     * 根据主键查询已分配的服务信息
     * @param id
     * @return
     */
    public AgedmallOnlineService queryAgedmallOnLineId (Integer id){
        AgedmallOnlineService agedmallOnlineService = agedmallOnlineServiceMapper.selectByPrimaryKey(id);
        return agedmallOnlineService;
    }

    /**
     * 获取服务订单费用
     * @param bigOrderId
     * @return
     */
    public BigDecimal getServiceOrderFee(long bigOrderId) {
        AgedmallServiceOrderExample agedmallServiceOrderExample = new AgedmallServiceOrderExample();
        List<Integer> noPayStatList = new ArrayList<>();
        noPayStatList.add(0);
        noPayStatList.add(6);
        noPayStatList.add(7);
        agedmallServiceOrderExample.createCriteria().andStatNotIn(noPayStatList).andOrderIdEqualTo(bigOrderId);
        List<AgedmallServiceOrder> orderList = agedmallServiceOrderMapper.selectByExample(agedmallServiceOrderExample);
        BigDecimal serviceOrderFee = new BigDecimal(0);
        orderList.stream().forEach(o->{
            BigDecimal sPrice = o.getServicePrice();
            serviceOrderFee.add(sPrice == null ? BigDecimal.ZERO : sPrice);
        });
        return serviceOrderFee;
    }
}
